package com.lancoo.klgcourseware.ui.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.ViewStub;

import androidx.viewpager.widget.ViewPager;

import com.lancoo.klgcourseware.R;
import com.lancoo.klgcourseware.base.BaseKlgFragment;
import com.lancoo.klgcourseware.base.BaseKlgPresenter;
import com.lancoo.klgcourseware.entity.ExpressPracticeModel;
import com.lancoo.klgcourseware.entity.WordArticulation;
import com.lancoo.klgcourseware.entity.bean.ErrorStates;
import com.lancoo.klgcourseware.entity.bean.KlgCardDialogConfigBean;
import com.lancoo.klgcourseware.entity.bean.KlgCommonBean;
import com.lancoo.klgcourseware.entity.bean.KlgDbConstant;
import com.lancoo.klgcourseware.manager.KlgCardDialogManager;
import com.lancoo.klgcourseware.presenter.BasicTrainPresenter;
import com.lancoo.klgcourseware.ui.adapter.ViewPagerFragmentAdapter;
import com.lancoo.klgcourseware.ui.fragment.basicTrain.BasicTrainBaseFragment;
import com.lancoo.klgcourseware.ui.fragment.basicTrain.SpellMemoryWriteFragment;
import com.lancoo.klgcourseware.ui.fragment.basicTrain.UsageTrainFragment;
import com.lancoo.klgcourseware.ui.fragment.operate.AlertBaseFragment;
import com.lancoo.klgcourseware.ui.fragment.operate.AlertPronunceTrainOperateFragment;
import com.lancoo.klgcourseware.ui.fragment.operate.AlertReadingTrainOperateFragment;
import com.lancoo.klgcourseware.ui.fragment.operate.AlertSlideOperateFragment;
import com.lancoo.klgcourseware.ui.fragment.operate.AlertSpellMemoryWriteTrainOperateFragment;
import com.lancoo.klgcourseware.ui.fragment.operate.AlertUsageTrainOperateFragment;
import com.lancoo.klgcourseware.ui.fragment.pronounceTrain.PronounceBaseFragment;
import com.lancoo.klgcourseware.ui.widget.CustomColorTransitionPagerTitleView;
import com.lancoo.klgcourseware.ui.widget.NoScrollViewPager;
import com.lancoo.klgcourseware.utils.KlgToolUtils;
import com.lancoo.klgcourseware.view.IBasicTrainView;
import com.stkouyu.entity.LgEvaluateObj;

import net.lucode.hackware.magicindicator.MagicIndicator;
import net.lucode.hackware.magicindicator.ViewPagerHelper;
import net.lucode.hackware.magicindicator.buildins.UIUtil;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.SimplePagerTitleView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by pengmi on 2019/8/15 16:43
 * Description:中级基础训练界面
 */
public class KlgIntermediateBasicTrainActivity extends KlgBaseTrainActivity implements IBasicTrainView,
        KlgCardDialogManager.KlgCardDismissListener, ViewPager.OnPageChangeListener {

    private static final String TAG = "KlgBasicTrainActivity";
    public static final String KEY_KLGCOMMONBEN="klgCommonBean";
    private KlgCommonBean commonBean;
    private WordArticulation wordArticulation;
    private BasicTrainPresenter mPresenter;
    private NoScrollViewPager viewPager;
    private List<BasicTrainBaseFragment> basicTrainBaseFragmentList;
    private int currentTrainIndex;
    private ViewPager spellAlertviewPager,phoneticAlertviewPager,usageAlertviewPager;
    private String syllable;
    private List<ExpressPracticeModel> expressPracticeModelList;
    private List<String> trainTagList;

    @Override
    protected int getContentViewId() {
        return R.layout.klg_activity_basic_train;
    }

    @Override
    protected String getTitleName() {
        return null;
    }

    @Override
    protected void setViewAndUpdata() {
        commonBean = (KlgCommonBean) getIntent().getSerializableExtra(KEY_KLGCOMMONBEN);
        if(commonBean==null){
            return;
        }
        initTimerMusic();
//        tv_title.setText(commonBean.getKlgName());
//        tv_title.setTextSize(18);
        mPresenter = new BasicTrainPresenter(this,commonBean.getKlgCode(),this,this);
        mPresenter.requestInfo();

    }

    public static void launch(Activity mActivity, KlgCommonBean commonBean){
        if(!requestPermission(mActivity)){
            return;
        }
        Intent mIntent=new Intent(mActivity, KlgIntermediateBasicTrainActivity.class);
        mIntent.putExtra(KEY_KLGCOMMONBEN,commonBean);
        mActivity.startActivityForResult(mIntent,102);
    }

    @Override
    public void loadingSuccess(WordArticulation wordArticulation, BaseKlgPresenter.LoadStatus status) {
        //弃掉，不用
    }

    @Override
    public void showLoadingPg() {
        showLoadingProgress();
    }

    @Override
    public void loadingFailure(ErrorStates errorStates) {
        showFailureLoad(errorStates);
    }

    @Override
    public void loadingSuccess(WordArticulation wordArticulation, List<ExpressPracticeModel> expressPracticeModelList) {
        dismissLoadingLayout();
        this.wordArticulation=wordArticulation;
        initData(wordArticulation,expressPracticeModelList);
        isLoadSuccess=true;
        invalidateOptionsMenu();
    }

    @Override
    protected void reloadData() {
        super.reloadData();
        if(mPresenter!=null){
            mPresenter.requestInfo();
        }
    }

    private void initData(WordArticulation wordArticulation, List<ExpressPracticeModel> expressPracticeModelList){
        this.expressPracticeModelList=expressPracticeModelList;
        trainTagList=new ArrayList<>();
        ViewStub stub = findViewById(R.id.viewstub_main_data);
        if(stub!=null){
            stub.inflate();
            List<String> moduleAttrs=new ArrayList<>();
            basicTrainBaseFragmentList = new ArrayList<>();
            if(TextUtils.equals("C",commonBean.getKlgType())){
                moduleAttrs.add(getString(R.string.klg_spell_memory));
                moduleAttrs.add(getString(R.string.klg_read_sentence_fill));
                SpellMemoryWriteFragment spellTrainFragment=new SpellMemoryWriteFragment();
                UsageTrainFragment pronunciatioTrainFragment=new UsageTrainFragment();
                basicTrainBaseFragmentList.add(spellTrainFragment);
                basicTrainBaseFragmentList.add(pronunciatioTrainFragment);
                Bundle mBundle=new Bundle();
                mBundle.putSerializable(BasicTrainBaseFragment.KEY_SPELL_ARTICULATION,wordArticulation);
                mBundle.putSerializable(KEY_KLGCOMMONBEN,commonBean);
                mBundle.putBoolean(BasicTrainBaseFragment.KEY_ISLASTTRAINMODEL,false);
                mBundle.putParcelableArrayList(BasicTrainBaseFragment.KEY_USAGE_TRAIN,(ArrayList) expressPracticeModelList);
                spellTrainFragment.setArguments(mBundle);
                pronunciatioTrainFragment.setArguments(mBundle);
                currentTrainTag=BasicTrainBaseFragment.TRAINTAG_SPELL_MEMORY_WRITE;
                syllable = wordArticulation.getSyllable();
                trainTagList.add(BasicTrainBaseFragment.TRAINTAG_SPELL_MEMORY_WRITE);
                trainTagList.add(BasicTrainBaseFragment.TRAINTAG_USAGE);
            }else{
                currentTrainTag=BasicTrainBaseFragment.TRAINTAG_USAGE;
//                trainTagList.add(BasicTrainBaseFragment.TRAINTAG_USAGE);
            }
            moduleAttrs.add(getString(R.string.klg_listen_retall));
            UsageTrainFragment usageTrainFragment=new UsageTrainFragment();
            basicTrainBaseFragmentList.add(usageTrainFragment);
            trainTagList.add(BasicTrainBaseFragment.TRAINTAG_USAGE);
            Bundle mBundle=new Bundle();
            mBundle.putParcelableArrayList(BasicTrainBaseFragment.KEY_USAGE_TRAIN,(ArrayList) expressPracticeModelList);
            mBundle.putString(BasicTrainBaseFragment.KEY_KLGTYPE,commonBean.getKlgType());
            mBundle.putBoolean(BasicTrainBaseFragment.KEY_ISLASTTRAINMODEL,true);
            usageTrainFragment.setArguments(mBundle);

            MagicIndicator magicIndicator = findViewById(R.id.magic_indicator);
            viewPager = findViewById(R.id.viewpager);
            viewPager.setScroll(true);
            viewPager.addOnPageChangeListener(this);
            initViewPagerAndMagicIndicator(magicIndicator,moduleAttrs);
        }
    }


    private void initViewPagerAndMagicIndicator(final MagicIndicator magicIndicator,final List<String> cModuleAttrsList){
        ViewPagerFragmentAdapter mAdapter=new ViewPagerFragmentAdapter(getSupportFragmentManager(),basicTrainBaseFragmentList);
        viewPager.setAdapter(mAdapter);
        viewPager.setOffscreenPageLimit(basicTrainBaseFragmentList.size());
        CommonNavigator commonNavigator = new CommonNavigator(this);
        commonNavigator.setAdjustMode(true);
        commonNavigator.setAdapter(new CommonNavigatorAdapter() {

            @Override
            public int getCount() {
                return cModuleAttrsList==null?0:cModuleAttrsList.size();
            }

            @Override
            public IPagerTitleView getTitleView(Context context, final int index) {
                SimplePagerTitleView simplePagerTitleView = new CustomColorTransitionPagerTitleView(context);
                simplePagerTitleView.setNormalColor(Color.parseColor("#81c2ee"));
                simplePagerTitleView.setSelectedColor(Color.parseColor("#009de6"));
                simplePagerTitleView.setText(cModuleAttrsList.get(index));
                simplePagerTitleView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        viewPager.setCurrentItem(index);
                    }
                });

                return simplePagerTitleView;
            }

            @Override
            public IPagerIndicator getIndicator(Context context) {
                LinePagerIndicator linePagerIndicator = new LinePagerIndicator(context);
                linePagerIndicator.setColors(Color.TRANSPARENT);
                linePagerIndicator.setLineWidth(KlgToolUtils.dip2px(context,50));
                linePagerIndicator.setRoundRadius(KlgToolUtils.dip2px(context,1.5f));
                linePagerIndicator.setMode(LinePagerIndicator.MODE_WRAP_CONTENT);
                linePagerIndicator.setYOffset(UIUtil.dip2px(context, 2));
                return linePagerIndicator;
            }

            @Override
            public float getTitleWeight(Context context, int index) {
                return 1.0f;
            }

        });
        magicIndicator.setNavigator(commonNavigator);
//        LinearLayout titleContainer = commonNavigator.getTitleContainer(); // must after setNavigator
//        titleContainer.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);
        ViewPagerHelper.bind(magicIndicator, viewPager);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.klg_menu_basic_train,menu);
        return true;
    }

    @Override
    public boolean onPrepareOptionsMenu(Menu menu) {
        menu.findItem(R.id.menu_train).setVisible(isLoadSuccess);
        menu.findItem(R.id.menu_train).getActionView().findViewById(R.id.img_train_pause).setOnClickListener(this);
        menu.findItem(R.id.menu_train).getActionView().findViewById(R.id.img_card).setOnClickListener(this);
        menu.findItem(R.id.menu_train).getActionView().findViewById(R.id.img_operate).setOnClickListener(this);
        return super.onPrepareOptionsMenu(menu);
    }

    @Override
    public void onClick(View v) {
        if(System.currentTimeMillis()-time<500){
            return;
        }
        time=System.currentTimeMillis();
        super.onClick(v);
        int id=v.getId();
        if(id==R.id.img_train_pause){
            Log.e("aaaa","img_train_pause");
            showTrainPauseDialog();
//            showEvaluationErrorDialog();
        }else if(id==R.id.img_card){
            Log.e("aaaa","img_card");
            pauseCurrentTrainProgress();
            KlgCardDialogConfigBean bean=new KlgCardDialogConfigBean();
            bean.setRetractCard(true);
            KlgCardDialogManager.opanKlgCardByList(this,getSupportFragmentManager(),commonBean,"",bean,this);
            enableShowPauseDialog=false;
        }else if(id==R.id.img_operate){
            Log.e("aaaa","img_operate");
            pauseCurrentTrainProgress();
            switch (currentTrainTag){
                case BasicTrainBaseFragment.TRAINTAG_SPELL:
                    showSpellTrainOperateAlertDialog(true);
                    break;
//                case BasicTrainBaseFragment.TRAINTAG_USAGE:
//                    showPhoneticTrainOperateAlertDialog();
//                    break;
                case BasicTrainBaseFragment.TRAINTAG_USAGE:
                    showUsageTrainOperateAlertDialog();
                    break;
            }
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
//        onCardDismiss();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }


    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {
        stopSpeechEvaluation(false);
        pauseStudyTimeTimer();
        if(basicTrainBaseFragmentList!=null){
            basicTrainBaseFragmentList.get(currentTrainIndex).pauseTrainStudy(true);
        }
        dismissEvaluationDialog();
        currentTrainIndex=position;
        currentTrainTag=trainTagList.get(position);
        if(currentTrainIndex==1){
            SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
            boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_PHONETIC_TRAIN, false);
            SharedPreferences.Editor edit = sharedPreferences.edit();
            if(!enableAutoTrain){
                haiTrainRecord=false;
                edit.putBoolean(KlgDbConstant.SP_ALERT_PHONETIC_TRAIN,true);
                edit.commit();
                showPhoneticTrainOperateAlertDialog();
            }else{
                startTrainCountTime(0);
            }
        }else if(currentTrainIndex==2){
            if(expressPracticeModelList==null){
                return;
            }
            SharedPreferences sharedPreferences=getSharedPreferences(KlgDbConstant.SP_KNOWLEDGE_COURSE, Context.MODE_PRIVATE);
            boolean enableAutoTrain = sharedPreferences.getBoolean(KlgDbConstant.SP_ALERT_USAGE_TRAIN, false);
            SharedPreferences.Editor edit = sharedPreferences.edit();
            if(!enableAutoTrain){
                haiTrainRecord=false;
                edit.putBoolean(KlgDbConstant.SP_ALERT_USAGE_TRAIN,true);
                edit.commit();
                showUsageTrainOperateAlertDialog();
            }else{
                startTrainCountTime(0);
            }
        }else {
            startTrainCountTime(0);
        }


    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }


    @Override
    public void onCardDismiss(int dismissType, int position, KlgCommonBean klgCommonBean, String tag) {
        Log.e("aaaa","onCardDismiss");
        enableShowPauseDialog=true;
        continueTrain();
    }

    /**
     * 继续训练
     */
    protected void continueTrain(){
        Log.e(TAG,"continueTrain");
        if(basicTrainBaseFragmentList!=null){
            basicTrainBaseFragmentList.get(viewPager.getCurrentItem()).resumeTrainStudy();
        }

    }

    /**
     * 重新训练（从当前模块开始）
     */
    protected void reTrainStart(){
        Log.e(TAG,"reTrainStart");
        if(TextUtils.equals(currentTrainTag,BasicTrainBaseFragment.TRAINTAG_SPELL)){//当前模式就是拼写训练
            if(basicTrainBaseFragmentList!=null&&basicTrainBaseFragmentList.size()>0){
                basicTrainBaseFragmentList.get(currentTrainIndex).pauseTrainStudy(true);
                startTrainCountTime(0);
            }
        }else if(TextUtils.equals(currentTrainTag,BasicTrainBaseFragment.TRAINTAG_PHONETIC)){//从发音训练进入拼写
//            if(viewPager!=null){
//                viewPager.setCurrentItem(0,false);
//            }
            resetPronunciationTrain();
//            enterPronounceSubTrainModel(PronounceBaseFragment.PronounceState.SLOWDREAD);
        }else{
            if(commonBean==null){
                return;
            }
            resetUsageTrain();
        }
    }


    /**
     * 开启模块训练
     */
    protected void startTrainAfterCountTime(){
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).startSubModeTrain();
        }
    }

    /**
     * 语音评测成功回调
     * @param grade 评测总得分
     * @param url 录音url
     * @param skegnResult 评测详情
     */
    protected void onEvaluationSuccessCallBack(int grade, String url, LgEvaluateObj skegnResult){
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).speechEvaluationSuccess(grade,url,skegnResult);
        }
    }

    /**
     * 进入下个训练模式
     */
    protected void enterNextTrainModel(){
        if(currentTrainIndex<basicTrainBaseFragmentList.size()-1){

            currentTrainTag=trainTagList.get(currentTrainIndex+1);
            viewPager.setCurrentItem(currentTrainIndex+1);
//            if(TextUtils.equals(BasicTrainBaseFragment.TRAINTAG_SPELL_MEMORY_WRITE,currentTrainTag)){
//                currentTrainTag=BasicTrainBaseFragment.TRAINTAG_USAGE;
//
//            }else if(TextUtils.equals(BasicTrainBaseFragment.TRAINTAG_PHONETIC,currentTrainTag)){
//                currentTrainTag=BasicTrainBaseFragment.TRAINTAG_USAGE;
//                viewPager.setCurrentItem(2);
//            }else if(TextUtils.equals(BasicTrainBaseFragment.TRAINTAG_USAGE,currentTrainTag)){
//            }
        }else{
//            enterUsageTrainResultActivity(0,0,0);
        }

    }

    protected KlgCommonBean getKlgCommonBean(){
        return commonBean;
    }


    /**
     * 进入发音训练子模式训练
     */
    protected void enterPronounceSubTrainModel(PronounceBaseFragment.PronounceState pronounceState ){
        Log.e("aaaaaaaaaaaa","currentTrainIndex:"+currentTrainIndex);
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).changePronounceTrainModel(pronounceState);
        }
    }

    /**
     * 暂停当前训练流程训练
     */
    protected void pauseCurrentTrainProgress(){
        stopSpeechEvaluation(false);
        pauseCountTimeTimer();
        pauseStudyTimeTimer();
        pauseDripMusicPlay();
        pauseTimerMusic();
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).pauseTrainStudy(false);
        }
    }

    /**
     * 重新开始用法训练
     */
    protected void resetUsageTrain(){
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).restartUsageTrain();
        }
    }


    /**
     * 重新开始发音训练
     */
    protected void resetPronunciationTrain(){
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).restartProunciatioTrain();
        }
    }

    /**
     * 3，2，1倒计时的进度
     * @param progress
     */
    protected void updateCountTimeProgress(int progress,int totalProgress){
        if(basicTrainBaseFragmentList!=null&&currentTrainIndex<basicTrainBaseFragmentList.size()){
            basicTrainBaseFragmentList.get(currentTrainIndex).updateCountTimeProgress(progress,totalProgress);
        }
    }

    @Override
    public void onBackPressed() {
        if(!enableShowPauseDialog){
            return;
        }
        super.onBackPressed();
    }

    /*****************引导图*************************/

    public void clostAlertOperate(){
        enableShowPauseDialog=true;
        if(spellAlertviewPager!=null&&spellAlertviewPager.getVisibility()==View.VISIBLE){
            spellAlertviewPager.setVisibility(View.GONE);
        }
        if(phoneticAlertviewPager!=null&&phoneticAlertviewPager.getVisibility()==View.VISIBLE){
            phoneticAlertviewPager.setVisibility(View.GONE);
        }
        if(usageAlertviewPager!=null&&usageAlertviewPager.getVisibility()==View.VISIBLE){
            usageAlertviewPager.setVisibility(View.GONE);
        }

        if(!haiTrainRecord){
            startTrainCountTime(0);
        }else{
            continueTrain();
        }

    }

    protected void showSpellMemoryWriteTrainOperateAlertDialog(boolean isOnlyShowSpellAlert){
        enableShowPauseDialog=false;
        ViewStub viewStub = findViewById(R.id.viewstub_spell_train_alert);
        if(viewStub!=null){
            viewStub.inflate();
            spellAlertviewPager = findViewById(R.id.alert_viewpager);
            AlertSlideOperateFragment fragment=new AlertSlideOperateFragment();
            AlertSpellMemoryWriteTrainOperateFragment alertSpellTrainOperateFragment=new AlertSpellMemoryWriteTrainOperateFragment();
            List<BaseKlgFragment> fragmentList=new ArrayList<>();
            if(!isOnlyShowSpellAlert){
                fragmentList.add(fragment);
            }
            fragmentList.add(alertSpellTrainOperateFragment);
            Bundle bundle=new Bundle();
            bundle.putString("klgName",commonBean.getKlgName());
            bundle.putBoolean("isOnlyShowSpellAlert",isOnlyShowSpellAlert);
            bundle.putSerializable(BasicTrainBaseFragment.KEY_SPELL_ARTICULATION,wordArticulation);
            alertSpellTrainOperateFragment.setArguments(bundle);
            ViewPagerFragmentAdapter mAdapter=new ViewPagerFragmentAdapter(getSupportFragmentManager(),fragmentList);
            spellAlertviewPager.setAdapter(mAdapter);
        }else {
            if(spellAlertviewPager!=null){
                spellAlertviewPager.setVisibility(View.VISIBLE);
                spellAlertviewPager.setCurrentItem(0,false);
            }
        }
    }

    protected void showPhoneticTrainOperateAlertDialog(){
        enableShowPauseDialog=false;
        ViewStub viewStub = findViewById(R.id.viewstub_phonetic_train_alert);
        if(viewStub!=null){
            viewStub.inflate();
            phoneticAlertviewPager = findViewById(R.id.alert_phonetic_viewpager);
            AlertBaseFragment alertReadingTrainOperateFragment=null;
            if(syllable.split("·").length>1){
                alertReadingTrainOperateFragment=new AlertPronunceTrainOperateFragment();
            }else{
                alertReadingTrainOperateFragment=new AlertReadingTrainOperateFragment();
            }
            List<BaseKlgFragment> fragmentList=new ArrayList<>();
            fragmentList.add(alertReadingTrainOperateFragment);
            Bundle bundle=new Bundle();
            bundle.putString("klgName",commonBean.getKlgName());
            bundle.putString("syllable",syllable);
            bundle.putString("phonetic",commonBean.getUs_phonetic());
            alertReadingTrainOperateFragment.setArguments(bundle);
            ViewPagerFragmentAdapter mAdapter=new ViewPagerFragmentAdapter(getSupportFragmentManager(),fragmentList);
            phoneticAlertviewPager.setAdapter(mAdapter);
        }else {
            if(phoneticAlertviewPager!=null){
                phoneticAlertviewPager.setVisibility(View.VISIBLE);
                phoneticAlertviewPager.setCurrentItem(0,false);
            }
        }
    }

    protected void showUsageTrainOperateAlertDialog(){
        enableShowPauseDialog=false;
        ViewStub viewStub = findViewById(R.id.viewstub_usage_train_alert);
        if(viewStub!=null){
            viewStub.inflate();
            usageAlertviewPager = findViewById(R.id.alert_usage_viewpager);
            AlertBaseFragment alertReadingTrainOperateFragment=new AlertUsageTrainOperateFragment();
            List<BaseKlgFragment> fragmentList=new ArrayList<>();
            fragmentList.add(alertReadingTrainOperateFragment);
            Bundle bundle=new Bundle();
            bundle.putParcelableArrayList(BasicTrainBaseFragment.KEY_USAGE_TRAIN,(ArrayList) expressPracticeModelList);
            alertReadingTrainOperateFragment.setArguments(bundle);
            ViewPagerFragmentAdapter mAdapter=new ViewPagerFragmentAdapter(getSupportFragmentManager(),fragmentList);
            usageAlertviewPager.setAdapter(mAdapter);
        }else{
            if(usageAlertviewPager!=null){
                usageAlertviewPager.setVisibility(View.VISIBLE);
                usageAlertviewPager.setCurrentItem(0,false);
            }
        }
    }
}
